package com.ruoyi.common.enums;


import com.ruoyi.common.exception.ServiceException;
import lombok.Getter;

import java.util.Arrays;

@Getter
public enum BaseIsStatusEnum implements BaseString {
    NORMAL("0", "正常"),
    EXCEPTION("1", "异常");

    private final String code;
    private final String desc;
    BaseIsStatusEnum(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    // 可选：每个枚举类可以定义自己的fromCode方法
    public static BaseIsStatusEnum fromCode(String code) {
        return BaseString.fromCode(BaseIsStatusEnum.class, code);
    }


    @Override
    public BaseIsStatusEnum valOf(String code) {
        return Arrays.stream(BaseIsStatusEnum.values()).filter(item -> item.code.equals(code)).findFirst().orElseThrow(() -> new ServiceException("枚举转换异常"));
    }
}
